package com.crealth.db;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;

import com.crealth.crmserver.WhitelistFilter;
import com.crealth.manager.MybatisManager;
import com.crealth.model.WhiteListIPModel;

public class WhitelistDb {
	
	public static List<WhiteListIPModel> selectAllWhiteList() {
		List<WhiteListIPModel> whitels = MybatisManager.whitelistMapper.selectAllWhiteList();
	
		return whitels;
	}
	
	public static void insertWhiteIP(String whiteIP, int companyID) {
		if (whiteIP == null || whiteIP.length() < 5) {
			return;
		}
		MybatisManager.whitelistMapper.insertWhiteIP(whiteIP, companyID);
		MybatisManager.commit();		
		try {    			
			InetAddress addr = InetAddress.getByName(whiteIP);
			WhitelistFilter.allow(addr);
		} catch (UnknownHostException e) {
		}		
	}
	
}
